import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/10 9:29
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    static final int MOD = 1337;

    public int superPow(int a, int[] b) {
        int ans = 1;
        for (int i = b.length - 1; i >= 0; --i) {
            ans = (int) ((long) ans * quickMul(a, b[i]) % MOD);
            // 从 a^1递推出 a^(10^k)
            a = quickMul(a, 10);
        }
        return ans;
    }
    /**
     * 快速幂
     * @param x x
     * @param n n
     * @return x^n
     */
    public int quickMul(int x, int n) {
        int res = 1;
        while (n != 0) {
            if ((n & 1) == 1) {
                res = (int) ((long) res * x % MOD);
            }
            x = (int) ((long) x * x % MOD);;
            n >>= 1;
        }
        return res;
    }
}
